def inp():
    n = int(input())
    a = input()
    return n,a

def spl(a):
    a_2 = a.split(' ')
    a_3 = a_2[:]
    return a_2,a_3

def strint(a_2,a_3):
    for i in range(0,len(a_2)):
        a_2[i] = int(a_2[i])
        a_3[i] = int(a_3[i])
    return a_2,a_3
        
def aver(a_2):
    return sum(a_2) // len(a_2)

def bm(a_2,a_3,ave):
    for i in range(0,len(a_3)):
        a_3[i] -= ave
        
def move(a_2,a_3,ave):
    time = 0
    for i in range(0,len(a_2)-1):
        bm(a_2,a_3,ave)
        if a_3[i]!= 0:
            temp = a_3[i]
            a_2[i + 1] += a_2[i] - temp
            a_2[i] = temp
        time += 1
    return time
        

def check(a_2):
    for i in range(0,len(a_2)):
        if a_2[i] == a_2[i + 1]:
            return False
    return True
        
def do(a_2):
    if check(a_2) == True:
        main()
    else:
        print(0)
 
def main():
    n,a = inp()
    a_2,a_3 = spl(a)
    a_2,a_3 = strint(a_2,a_3)
    if check(a_2) == False:
        print(0)
        return
    ave = aver(a_2)
    print(move(a_2,a_3,ave))
    
    
main()